package com.megvii.corelib.util;

/**
 * Created by linyue on 15/12/29.
 */

import android.app.AlertDialog;
import android.content.Context;

import com.megvii.corelib.components.DeviceSelectView;

/**
 * Created by linyue on 15/12/29.
 */
public class DeviceSelectDialog implements DeviceSelectView.DeviceSelectListener
{
    private DeviceSelectDialogListener listener;

    private AlertDialog dialog;

    /**
     * @param context
     * @param listener
     * @param titleText null就显示默认的
     */
    public void showDeviceSelector(Context context, final DeviceSelectDialogListener listener,
            String titleText)
    {
        this.listener = listener;
        final DeviceSelectView view = new DeviceSelectView(context);
        view.setTitleText(titleText);
        view.setListener(this);
        AlertDialog.Builder builder = new AlertDialog.Builder(context,
                AlertDialog.THEME_HOLO_LIGHT);
        builder.setView(view);
        dialog = builder.show();
        dialog.setCanceledOnTouchOutside(true);
    }

    @Override
    public void onChooseDevice(DeviceSelectView.Device device)
    {
        dialog.hide();
        if (listener != null)
        {
            listener.onSelect(device);
        }
    }

    @Override
    public void onCancel()
    {
        dialog.hide();
    }

    public interface DeviceSelectDialogListener
    {
        public void onSelect(DeviceSelectView.Device device);
    }
}

